import 'package:daoyi_ui_admin_getx/app/common/styles/theme.dart';
import 'package:daoyi_ui_admin_getx/app/modules/not_found/not_found_view.dart';
import 'package:daoyi_ui_admin_getx/app/routes/app_pages.dart';
import 'package:daoyi_ui_admin_getx/generated/locales.g.dart';
import 'package:flutter/material.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:get/get.dart';

import 'controllers/app_init_controller.dart';

class Application extends StatelessWidget {
  const Application({super.key});

  @override
  Widget build(BuildContext context) {
    WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
    FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
    return GetMaterialApp(
      title: "Application",
      initialRoute: AppPages.INITIAL,
      getPages: AppPages.routes,
      unknownRoute: GetPage(
        name: Routes.NOT_FOUND,
        page: () => const NotFoundView(),
      ),
      theme: AppTheme.light,
      darkTheme: AppTheme.dark,
      translationsKeys: AppTranslation.translations,
      locale: const Locale('zh', 'CN'),
      fallbackLocale: const Locale('zh', 'CN'),
    );
  }

  @override
  StatelessElement createElement() {
    Get.put(AppInitController());
    Get.changeThemeMode(ThemeMode.light);
    return super.createElement();
  }
}
